local skel = fk.CreateSkill {
  name = "emo__shenbian",
}

skel:addEffect("viewas", {
  anim_type = "support",
  pattern = "slash,peach,nullification",
  prompt = "#emo__shenbian",
  interaction = function (self, player)
    local all_choices = string.split(self.pattern, ",")
    local choices = player:getViewAsCardNames(skel.name, all_choices)
    if #choices == 0 then return end
    return UI.CardNameBox {choices = choices}
  end,
  card_filter = function (self, player, to_select, selected)
    local c = Fk:getCardById(to_select)
    return #selected < 2 and table.every(selected, function(id)
      return Fk:getCardById(id).suit == c.suit
    end)
  end,
  view_as = function (self, player, cards)
    local choice = self.interaction.data
    if #cards ~= 2 or choice == nil then return nil end
    if choice == "slash" then choice = "thunder__slash" end
    local c = Fk:cloneCard(choice)
    c.skillName = self.name
    c:addSubcards(cards)
    return c
  end,
  before_use = function(self, player, use)
    local room = player.room
    use.extra_data = use.extra_data or {}
    use.extra_data.emo__shenbianSuit = Fk:getCardById(use.card.subcards[1]).suit
    if use.card.name == "nullification" then
      use.disresponsiveList = table.simpleClone(player.room.players)
    elseif use.card.trueName == "slash" then
      for _, p in ipairs(room:getOtherPlayers(player)) do
        if not table.contains(use.tos, p) and not player:isProhibited(p, use.card) then
          table.insert(use.tos, p)
        end
      end
    end
  end,
  after_use = function(self, player, use)
    if not player.dead then
      local suit = (use.extra_data or {}).emo__shenbianSuit
      if suit and table.every(player:getCardIds("h"), function (id)
        return Fk:getCardById(id).suit ~= suit
      end) then
        player:drawCards(2, self.name)
      end
    end
  end,
  enabled_at_play = function(self, player)
    return true
  end,
  enabled_at_response = function (self, player, response)
    return not response and #player:getCardIds("he") > 1
  end,
})

skel:addEffect("targetmod", {
  bypass_distances = function(self, player, skill, card)
    return card and card.trueName == "slash" and table.contains(card.skillNames, skel.name)
  end,
})

Fk:loadTranslationTable{
  ["emo__shenbian"] = "神变",
  [":emo__shenbian"] = "你可以将两张花色相同的牌当【桃】、不可响应的【无懈可击】、指定所有其他角色的雷【杀】使用，然后若你没有此花色的手牌，你摸两张牌。",
  ["#emo__shenbian"] = "神变：将两张花色相同的牌当【桃】、【无懈可击】、或雷【杀】使用",

  ["$emo__shenbian1"] = "藏巧于拙，用晦而明",
  ["$emo__shenbian2"] = "寓清于浊，以屈为伸",
}


return skel
